package com.javabasic.net.socket;

import org.junit.Test;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author xiongmin
 * @Description TODO
 * @Date 2019/10/22 14:23
 * @Version 1.0
 **/
public class Client {

    static Scanner cin = new Scanner(System.in);

    public static void main(String[] args) {
        byte[] bytes = new byte[1024];
        try {
            Socket socket = new Socket("127.0.0.1", 9999);
            OutputStream outputStream = socket.getOutputStream();

            String message = cin.next();
            outputStream.write(message.getBytes());
            outputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void  test() {
        byte[] bytes = new byte[1024];
        try {
            Socket socket = new Socket("127.0.0.1", 9999);
            OutputStream outputStream = socket.getOutputStream();

            String message = cin.next();
            outputStream.write(message.getBytes());
            outputStream.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
